Micron Document
Fox's Git Mirrors

Node / styrene-lab / omegon-extension-py.git rns://e35de29a61974cd952fde3fe9c8500d5/styrene-lab/omegon-extension-py.git


>omegon-extension (Python)

Python SDK for building Omegon extensions.

Install

T282828
pip install omegon-extension

Quick start

T282828
import asyncio
from omegon_extension import Extension, serve, tool

class WeatherExtension(Extension):
name = "weather"
version = "0.1.0"

@tool(
description="Get the current weather for a city",
params={
"city": {"type": "string", "description": "City name"},
"units": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "Temperature units"},
},
required=["city"],
)
async def get_weather(self, city: str, units: str = "celsius") -> str:
# Your implementation here
return f"Weather in {city}: 22°{'C' if units == 'celsius' else 'F'}, sunny"

@tool(description="List supported cities")
def list_cities(self) -> list:
return [
{"type": "text", "text": "Supported: London, Tokyo, New York, Sydney"}
]

asyncio.run(serve(WeatherExtension()))

Save as T383838weather_ext.py, create a T383838manifest.toml:

T282828
[extension]
name = "weather"
version = "0.1.0"
description = "Weather information for agents"
sdk_version = "0.15"

[runtime]
type = "native"
binary = "python3 weather_ext.py"

[startup]
ping_method = "get_tools"
timeout_ms = 5000

Install and test:

T282828
omegon extension install .

API

Extension base class

T282828
class MyExtension(Extension):
name = "my-ext" # Must match manifest.toml
version = "0.1.0"

@tool decorator

T282828
@tool(
description="What the tool does", # Required
label="Display Name", # Optional (auto-generated from method name)
params={"arg": {"type": "string"}}, # Optional, JSON Schema properties
required=["arg"], # Optional, required parameter names
)
async def my_tool(self, arg: str) -> str:
return "result"

Return values are auto-wrapped:
• T383838str → T383838{"content": [{"type": "text", "text": "..."}]}
• T383838dict → returned as-is (must include T383838"content" key)
• T383838list → T383838{"content": [...]}

Secrets

T282828
class MyExtension(Extension):
@tool(description="Use an API")
async def call_api(self) -> str:
token = self.get_secret("API_TOKEN")
if not token:
return "No API token configured"
# use token...

Secrets are delivered by omegon via T383838bootstrap_secrets RPC — never from environment variables.

Custom RPC handling

Override T383838handle_rpc for full control:

T282828
class MyExtension(Extension):
async def handle_rpc(self, method: str, params: dict):
if method == "get_tools":
return [...]
if method == "my_custom_method":
return {"custom": "response"}
raise RpcError.method_not_found(method)

Error handling

T282828
from omegon_extension import RpcError

@tool(description="Divide two numbers")
async def divide(self, a: float, b: float) -> str:
if b == 0:
raise RpcError.invalid_params("cannot divide by zero")
return str(a / b)

Protocol

This SDK implements the Omegon Extension Protocol — JSON-RPC 2.0 over stdin/stdout.

SDKs in other languages

┌────────────┬──────────────────────────────┬───────────────────────────────────┐
│ Language │ Package │ Status │
├────────────┼──────────────────────────────┼───────────────────────────────────┤
Rust │ T383838omegon-extension (crates.io) │ Stable — canonical implementation │
Python │ T383838omegon-extension (PyPI) │ Stable │
Go │ planned │ — │
TypeScript │ planned │ — │
C/Swift │ planned │ — │
└────────────┴──────────────────────────────┴───────────────────────────────────┘

License

MIT

Served by rngit 1.5.0 - Generated in 0.05s